package com.zkyc.framework.schedulejob.task;


import com.zkyc.framework.common.mapper.ActivityMapper;
import com.zkyc.framework.common.pojo.Activity;
import com.zkyc.framework.schedulejob.config.JedisPoolFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Set;
import static com.zkyc.framework.common.constant.Constant.*;

@Component
public class ActivityClickTask {

    @Autowired
    private ActivityMapper activityMapper;
    @Scheduled(cron = "*/30 * * * * ?")
    public void process() {
        Set<String> scan = JedisPoolFactory.scan(REDIS_PREFIX + ACTIVITYCLICK);
        if (scan != null) {
            for (String key : scan) {
                Integer count = Integer.parseInt(JedisPoolFactory.select(key));
                String[] keySpilt = key.split("k_");
                String activityIdStr = keySpilt[1];
                Integer activityId = Integer.valueOf(activityIdStr);
                Activity activity = activityMapper.selectById(activityId);
                if (activity != null) {
                    activity.setHitNumber(count);
                    activityMapper.updateById(activity);
                }
            }
        }
    }

}

